﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web_froms
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        //登录
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            var username = uid.Text.Trim();
            var password = pwd.Text.Trim();
            var sql = string.Format("select * from Users where UserName='{0}'", username);
            var dt = DbHelper.GetDatatable(sql);
            if (username == "")
            {
                Response.Write(@"<script>alert('用户名不能为空！')</script>");
            }
            else
                if (password == "")
            {
                Response.Write(@"<script>alert('密码不能为空！')</script>");
            }
            else
                if (dt.Rows.Count > 0)
            {
                var item = dt.Rows[0];
                var isactived = (bool)item.ItemArray[3];
                var isdelete = (bool)item.ItemArray[4];
                var user = item.ItemArray[1].ToString();
                var pasd = item.ItemArray[2].ToString();
                if (isdelete)
                {
                    Response.Write(@"<script>alert('该用户已被删除')</script>");
                }
                else
                    if (isactived)
                {
                    if (password == pasd)
                    {
                        Response.Redirect("default.aspx");
                    }
                    else
                    {
                        Response.Write(@"<script>alert('用户名或密码错误！')</script>");
                    }
                }
                else
                {
                    Response.Write(@"<script>alert('用户被冻结，请联系管理员！')</script>");
                }
            }
            else
            {
                Response.Write(@"<script>alert('用户未注册！')</script>");
            }
        }

        //注册
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            Response.Redirect("Register.aspx");
        }
    }
}